<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>咨询测算查询</title> <%include("/common/include.html"){}%>
<link rel="stylesheet" href="${cxt!}/sb/plugins/ztree/css/zTreeStyle/zTreeStyle.css" type="text/css">
<style type="text/css">
.textbox {
	padding-right: 0px;
	background: url("${cxt !}/sb/themes/insdep/images/combo_arrow.png")
		no-repeat scroll right center transparent;
}
</style>
</head>
<body class="easyui-layout">
	<div id="dianyuanmessage" class="easyui-window" title="店员" data-options="collapsible:false,minimizable:false,maximizable:false,closable:true,resizable:true" style="width:750px;height:400px;padding:5px;" data-options="cls:'theme-panel-orange'" closed="true">
		<table id="tablevisit"></table>
	</div>
	<div data-options="region:'north',split: true,title:'快速查询'" style="height: 200px; padding: 10px;">
		<form id="measureStatisticFrom" action="${cxt!}/measureStatistic/excel">
			<div style="margin-bottom: 10px; float: left; margin-right: 10px;">
				<label class="label-top" style="width: 100%; display: block;">开始时间</label>
				<input name="_query.startTime" value='${date()}' class="easyui-datebox theme-textbox-radius"
					style="height: 32px; width: 212px; text-align: center" 
						data-options="editable: false,icons:[{
		                        iconCls:'icon-clear',
		                        handler: function(e){
		                            $(e.data.target).datetimespinner('clear');
		                        }
		                    }]"/>
			</div>
			<div style="margin-bottom: 10px; float: left; margin-right: 10px;">
				<label class="label-top" style="width: 100%; display: block;">结束时间</label>
				<input name="_query.endTime" value='${date()}' class="easyui-datebox theme-textbox-radius" style="height: 32px; width: 212px; text-align: center"
						data-options="editable: false,icons:[{
		                        iconCls:'icon-clear',
		                        handler: function(e){
		                            $(e.data.target).datetimespinner('clear');
		                        }
		                    }]"/>
			</div>
			<div style="margin-bottom: 10px; float: left; margin-right: 10px;">
				<label class="label-top" style="width: 100%; display: block;">代理商/门店</label>
				<input id="organ" type="text" readonly style="width: 200px; height: 30px; padding-left: 10px; text-align: center"
					onclick="showMenu(); return false;" class="textbox" value="${curOrgan.name! }" />
				<input name="organIds" id="organIds" type="hidden" value="${curOrgan.ids! }">
			</div>
			<div style="margin-bottom: 10px; float: left; margin-right: 10px;">
				<label class="label-top" style="width: 100%; display: block;">市场负责人</label>
				<input id="organMangerIds" name="organMangerIds" class="easyui-combobox theme-textbox-radius"
					style="width: 212px; height: 32px; text-align: center;" data-options="editable: false">
			</div>
			<div style="margin-bottom: 10px; float: left; margin-top: 16px; margin-right: 10px;">
				<a href="#" onclick='searchFrom()' class="easyui-linkbutton" data-options="iconCls:'icon-search'" style="width: 212px">搜索</a>
			</div>
			<div style="margin-bottom: 10px;float:left;">
				<label class="label-top" style="width: 100%; display: block;">导出</label>
				<a href="#" onclick="queryCustomerExcel()" class="easyui-linkbutton" data-options="iconCls:'icon-pageexcel'" style="width:212px">导出</a>
			</div>
		</form>
	</div>
	<div data-options="region:'center',border: false" style="overflow-x: hidden;">
		<table id="measureStatisticTable" style="width: 100%; height: 100%;">
		</table>
	</div>
	<div id="menuContent" class="menuContent" style="display: none; position: absolute; z-index: 10;">
		<ul id="organSelectTree" class="ztree" style="margin-top: 0; width: 200px;"></ul>
	</div>
	<script type="text/javascript">
		var $form = $('#measureStatisticFrom');
		function searchFrom() {
			$("#measureStatisticTable").datagrid('load',
					sy.serializeObject($form));
		}
		$(function() {
			var $form_div = $("#measureStatisticFrom div");
			winResize($form_div);
			$(window).resize(function() {//当调整浏览器窗口的大小时，发生 resize 事件
				winResize($form_div);
			})
		})
		function initMeasureStatisticTable(orgainIds) {

			var columnsAll = new Array();
			columnsAll.push({field:'xxx',title:'隶属',width:60,align:'center',rowspan:2,colspan:7});
			columnsAll.push({field:'xxx',title:'基本信息',width:60,align:'center',rowspan:2,colspan:6});
			columnsAll.push({field:'xxx',title:'xxx',width:60,align:'center'});
			
			var columnsAll2 = new Array();
			columnsAll2.push({field:'xxx',title:'xxx',width:60,align:'center'});
			
			var columnsAll3 = new Array();
			columnsAll3.push({field:'marketingmanager',title:'市场经理',width:60,align:'center'});
			columnsAll3.push({field:'provinces',title:'省份',width:60,align:'center'});
			columnsAll3.push({field:'agent',title:'代理商',width:60,align:'center'});
			columnsAll3.push({field:'areamanager',title:'片区经理',width:60,align:'center'});
			columnsAll3.push({field:'nameoforganization',title:'机构名称',width:60,align:'center'});
			columnsAll3.push({field:'shopmanager',title:'店长',width:60,align:'center'});
			columnsAll3.push({field:'nameofclerk',title:'店员',width:60,align:'center'});
			columnsAll3.push({field:'nameofcustomer',title:'顾客姓名',width:75,align:'center'});
			columnsAll3.push({field:'firstintoshop',title:'首次到店日期',width:75,align:'center'});
			columnsAll3.push({field:'firstweight',title:'首次到店体重',width:75,align:'center'});
			columnsAll3.push({field:'standardweight',title:'标准体重',width:75,align:'center'});
			columnsAll3.push({field:'shouldloseweight',title:'应减体重',width:75,align:'center'});
			columnsAll3.push({field:'umnberofcourse',title:'疗程数',width:75,align:'center'});
			columnsAll3.push({field:'xxx',title:'xxx',width:60,align:'center'});
			
			$('#measureStatisticTable').datagrid({
				cls : "theme-datagrid",
				singleSelect : true,
				rownumbers : true, //显示序号
				url : "${cxt!}/monthshopmanagerandemployeekeyindex/query",
				queryParams : sy.serializeObject($form),
				method : 'post',
				collapsible : true,
				columns : [columnsAll,columnsAll2,columnsAll3],
				onLoadSuccess : function() {

				},
				onClickRow : function(rowIndex, rowData) {
				}
			});
		}
	</script>
	<script type="text/javascript">
		var setting = {
			async : {
				enable : true,
				url : '${cxt!}/common/getOrgenTree',
				autoParam : [ "id=ids" ],//, "name=n", "level=lv"
				type : "post"
			},
			view : {
				dblClickExpand : false
			},
			data : {
				simpleData : {
					enable : true
				}
			},
			callback : {
				onClick : onClick,
				onAsyncSuccess : organTreeOnAsyncSuccess
			}
		};
		//初始化市场负责人下拉框
		function initMangerSelect(ids) {
			var url = "/common/getOrganManger";
			var param = {
				'ids' : ids
			};
			var data = common_ajax.ajaxFunc(url, param, "json");
			data.unshift({
				'ids' : '-1',
				'name' : '-请选择-'
			});
			$('#organMangerIds').combobox({
				data : data,
				valueField : 'ids',
				textField : 'name',
				onLoadSuccess : function() {
					var val = $(this).combobox('getData');
					for ( var item in val[0]) {
						if (item == 'ids') {
							$(this).combobox('select', val[0][item]);
						}
					}
				}
			});
		}
		var flag = 0;
		function organTreeOnAsyncSuccess(event, treeId, msg) {
			if (flag == 0) {
				var organTree = $.fn.zTree.getZTreeObj("organSelectTree");
				var nodes = organTree.getNodes();
				initMangerSelect(nodes[0].id);
				initMeasureStatisticTable(nodes[0].id);
				flag = 1;
			}
		}
		function onClick(e, treeId, treeNode) {
			var zTree = $.fn.zTree.getZTreeObj("organSelectTree");
			var path = "";
			var sNodes = zTree.getSelectedNodes();
			if (sNodes.length > 0) {
				var node = sNodes[0].getPath();
				for (var i = 0; i < node.length; i++) {
					path += node[i].name + "/"
				}
			}
			var cityObj = $("#organ");
			cityObj.attr("value", path);
			$("#organIds").attr("value", treeNode.id);
			initMangerSelect(treeNode.id);
			hideMenu();
		}
		function showMenu() {
			var cityObj = $("#organ");
			var cityOffset = $("#organ").offset();
			$("#menuContent").css({
				left : cityOffset.left + "px",
				top : cityOffset.top + cityObj.outerHeight() + "px"
			}).slideDown("fast");

			$("body").bind("mousedown", onBodyDown);
		}
		function hideMenu() {
			$("#menuContent").fadeOut("fast");
			$("body").unbind("mousedown", onBodyDown);
		}
		function onBodyDown(event) {
			if (!(event.target.id == "menuBtn"
					|| event.target.id == "menuContent" || $(event.target)
					.parents("#menuContent").length > 0)) {
				hideMenu();
			}
		}
		$.fn.zTree.init($("#organSelectTree"), setting);
		function btn2(ids){
			$('#dianyuanmessage').window('open');
			$('#tablevisit').datagrid({
				queryParams: {
					'_query.ids': ids,
				},
				singleSelect: true,
				rownumbers: true, //显示序号
				pagination: true,
				pageSize: 10,
				url:'scallVisit/queryByCallVisit',
				collapsible: true,
				columns:[[
					{field:'visitdate',title:'回访时间',width:130,align:'center'},
					{field:'subject',title:'回访内容',width:130,align:'center'},
					{field:'issatisfaction',title:'满意度',width:130,align:'center',
						formatter:function(value,row,index){
							if(value == 1){
								return '满意';
							}else if(value==2){
								return '一般';
							}else if(value==3){
								return '差';
							}
						}},
					{field:'advice',title:'顾客建议',width:130,align:'center'},
				]]
			});
		};
		function queryCustomerExcel(){
			$('#measureStatisticFrom').submit();
		}
	</script>
</body>
</html>
